<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>canvas</title>
    <style>
      #canvas {
        background-color: gray;
      }
    </style>
  </head>
  <body>
    <canvas id="canvas" width="800" height="400"></canvas>
    <script type="text/javascript">
      // 获取canvas元素
      const canvas = document.getElementById('canvas')
      //获取花臂
      const context = canvas.getContext('2d')
      context.beginPath()
      //绘画
      context.strokeStyle = 'pink'
      // 画线
      context.moveTo(100, 100) //把路径移动到画布中的指定点，不创建线条
      context.lineTo(200, 200) //添加一个新点，然后在画布中创建从该点到最后指定点的线条
      // 画线 moveTo(x, y) lineTo(x, y)
      context.lineTo(200, 150)
      context.stroke() //闭合
      context.closePath()

      // 画矩形 strokeRect(x, y, width, height)
      context.strokeRect(300, 100, 100, 100)

      context.fillStyle = 'yellowgreen'
      context.fillRect(300, 250, 100, 100)

      context.beginPath()
      //画圆arc(x, y, radius, starAngle, endAngle, anticlockwise)
      context.arc(600, 200, 50, 0, Math.PI, true)
      context.stroke() // 闭合
      context.closePath()

      //   context.clearRect(0,0,800,400)
      context.font = '20px 黑体'
      context.fillText('吊毛', 600, 100)
    </script>
  </body>
</html>
